package com.power.sifa.approve.dao;

import com.power.sifa.approve.model.Apl_arrive_detail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 送达记录详情 持久层(hibernate)
 */

public interface Apl_arrive_detailDao extends JpaRepository<Apl_arrive_detail, Serializable>, JpaSpecificationExecutor<Apl_arrive_detail>, Repository<Apl_arrive_detail, Serializable>, Apl_arrive_detailDaoCustom<Apl_arrive_detail, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Apl_arrive_detail s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);


   /**
    * 根据applyid查询列表
    * @param applyIds
    * @return
    */
   @Query("from Apl_arrive_detail s where s.applyid in (:applyIds) ")
   List<Apl_arrive_detail> findDetailByApplyIds(@Param("applyIds") List<String> applyIds);

   /**
    * 根据userid查询待处理的通知
    * @param userid
    * @return
    */
   @Query(" from Apl_arrive_detail s where s.noticeperid = :userid and s.sendstatus = 3201 order by s.createtime asc")
   List<Apl_arrive_detail> getByNoticeUserId(String userid);


   /**
    * 根据applyid查询最近一条待处理的通知
    * @param applyid
    * @return
    */
   @Query(" from Apl_arrive_detail s where s.applyid = :applyid and s.sendstatus = 3201 order by s.createtime desc")
   List<Apl_arrive_detail> getByApplyid(String applyid);
}
